/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Business;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Storm^^Rain
 */
public class Supplier_MD extends AbstractTableModel {

    private List<Supplier_BS> suppliers;
    private final String columnsName[] = {"Code", "Name","Phone","Type","Address"};
    private final Class columnsClass[] = {String.class, String.class, String.class, String.class, String.class};
    
    public Supplier_MD(List<Supplier_BS> suppliers) {
        this.suppliers = suppliers;
    }
    
    public int getRowCount() {
        return suppliers.toArray().length;
    }

    public int getColumnCount() {
        return columnsName.length;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return suppliers.get(rowIndex).getsID();
            
            case 1:
                return suppliers.get(rowIndex).getsName();
                
            //case 2:
              //  return suppliers.get(rowIndex).getsfullName();
                
            case 2:
                return suppliers.get(rowIndex).getsPhone();

           // case 4:
             //   return suppliers.get(rowIndex).getsFax();

            case 3:
                switch(suppliers.get(rowIndex).getsType()) {
                    case 0:
                        return "Distributor";

                    case 1:
                        return "Dealer";

                    case 2:
                        return "Who sale Retailer";

                    default:
                        return "";
                }
            case 4:
                return suppliers.get(rowIndex).getsAddress();

           // case 7:
             //   return suppliers.get(rowIndex).getsEmail();

           // case 8:
             //   return suppliers.get(rowIndex).getsWebsite();

                
            default:
                return null;
                                  
        }
    }
    
    @Override
    public String getColumnName(int iCol) {
        return columnsName[iCol];        
    }

    @Override
    public Class getColumnClass(int iCol) {
        return columnsClass[iCol];
    }


    public Supplier_BS getSupplier(int rowIndex) {
        fireTableDataChanged();
        return suppliers.get(rowIndex);
    }
    public void createSupplier(Supplier_BS supplier){
        fireTableDataChanged();
    }

    public void updateSupplier(Supplier_BS supplier) {
        fireTableDataChanged();
    }

    public void deleteSupplier(Supplier_BS supplier) {
        suppliers.remove(supplier);
        fireTableDataChanged();
    }
}
